home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.text;
-
- import com.sun.java.swing.event.DocumentEvent;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.Shape;
-
- class WrappedPlainView$WrappedLine extends View {
- // $FF: synthetic field
- WrappedPlainView this$0;
- int nlines;
-
- // $FF: synthetic method
- WrappedPlainView$WrappedLine(WrappedPlainView this$0, Element elem) {
- super(elem);
- this.this$0 = this$0;
- }
-
- final int calculateLineCount() {
- int nlines = 0;
- int p1 = ((View)this).getEndOffset();
-
- int p;
- for(int p0 = ((View)this).getStartOffset(); p0 < p1; p0 = p == p0 ? p1 : p) {
- ++nlines;
- p = this.this$0.calculateBreakPosition(p0, p1);
- }
-
- return nlines;
- }
-
- public float getPreferredSpan(int axis) {
- switch (axis) {
- case 0:
- return (float)this.this$0.getWidth();
- case 1:
- if (this.nlines == 0 || this.this$0.widthChanging) {
- this.nlines = this.calculateLineCount();
- }
-
- int h = this.nlines * this.this$0.metrics.getHeight();
- return (float)h;
- default:
- throw new IllegalArgumentException("Invalid axis: " + axis);
- }
- }
-
- public void paint(Graphics g, Shape a) {
- Rectangle alloc = (Rectangle)a;
- int y = alloc.y + this.this$0.metrics.getAscent();
- int x = alloc.x;
- int p1 = ((View)this).getEndOffset();
-
- for(int p0 = ((View)this).getStartOffset(); p0 < p1; y += this.this$0.metrics.getHeight()) {
- int p = this.this$0.calculateBreakPosition(p0, p1);
- this.this$0.drawLine(p0, p, g, x, y);
- p0 = p == p0 ? p1 : p;
- }
-
- }
-
- public Shape modelToView(int pos, Shape a) throws BadLocationException {
- Rectangle alloc = (Rectangle)a;
- alloc.height = this.this$0.metrics.getHeight();
- alloc.width = 1;
- int p1 = ((View)this).getEndOffset();
-
- for(int p0 = ((View)this).getStartOffset(); p0 < p1; alloc.y += alloc.height) {
- int p = this.this$0.calculateBreakPosition(p0, p1);
- if (pos >= p0 && pos < p) {
- this.this$0.loadText(p0, pos);
- alloc.x += Utilities.getTabbedTextWidth(this.this$0.lineBuffer, this.this$0.metrics, alloc.x, this.this$0, p0);
- return alloc;
- }
-
- p0 = p == p0 ? p1 : p;
- }
-
- throw new BadLocationException((String)null, pos);
- }
-
- public int viewToModel(float fx, float fy, Shape a) {
- Rectangle alloc = (Rectangle)a;
- ((View)this).getDocument();
- int x = (int)fx;
- int y = (int)fy;
- if (y < alloc.y) {
- return ((View)this).getStartOffset();
- } else if (y > alloc.y + alloc.height) {
- return ((View)this).getEndOffset() - 1;
- } else {
- alloc.height = this.this$0.metrics.getHeight();
- int p1 = ((View)this).getEndOffset();
-
- for(int p0 = ((View)this).getStartOffset(); p0 < p1; alloc.y += alloc.height) {
- int p = this.this$0.calculateBreakPosition(p0, p1);
- if (y >= alloc.y && y < alloc.y + alloc.height) {
- if (x < alloc.x) {
- return p0;
- }
-
- if (x > alloc.x + alloc.width) {
- return p;
- }
-
- int n = Utilities.getTabbedTextOffset(this.this$0.lineBuffer, this.this$0.metrics, alloc.x, x, this.this$0, p0);
- return Math.min(p0 + n, p1 - 1);
- }
-
- p0 = p == p0 ? p1 : p;
- }
-
- return ((View)this).getEndOffset() - 1;
- }
- }
-
- public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
- int n = this.calculateLineCount();
- if (this.nlines != n) {
- this.nlines = n;
- this.this$0.preferenceChanged(this, false, true);
- }
-
- if (a != null) {
- Component c = ((View)this).getContainer();
- Rectangle alloc = (Rectangle)a;
- c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
- }
-
- }
-
- public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
- int n = this.calculateLineCount();
- if (this.nlines != n) {
- this.nlines = n;
- this.this$0.preferenceChanged(this, false, true);
- }
-
- if (a != null) {
- Component c = ((View)this).getContainer();
- Rectangle alloc = (Rectangle)a;
- c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
- }
-
- }
- }
-